from django.contrib.staticfiles.storage import staticfiles_storage
from django.urls import reverse

from jinja2 import Environment

from orders.models import OrderInfo


def environment(**options):
    env = Environment(**options)
    env.globals.update({
        'static': staticfiles_storage.url,
        'url': reverse,
    })
    env.filters['new_tel'] = new_tel
    env.filters['status'] = status
    return env


def new_tel(value):
    return value[:3] + "****" + value[7:]


def status(value):
    code_str_dict = dict(OrderInfo.ORDER_STATUS_CHOICES)
    return code_str_dict[value]

